package com.explorati.LeetCode349.insersection;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ Author : Weijian_Wang
 * @ Date : Created in 22:56 2020/10/22 0022
 * @ Description ：
 */
public class Solution2 {
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set1 = new HashSet<>();
        for(int nums : nums1) {
            set1.add(nums);
        }

        Set<Integer> set2 = new HashSet<Integer>();
        for(int nums : nums2) {
            if(set1.contains(nums)) {
                set2.add(nums);
            }
        }

        int[] res = new int[set2.size()];
        Iterator iter = set2.iterator();
        int i = 0;
        while(iter.hasNext()) {
            res[i] = (int)iter.next();
            i ++;
        }
        return res;
    }
}
